<?php	namespace Home\Model;
use Hdphp\Model\Model;
/**
 * 订单表
 */
class OrderLSuccess extends Model
{
	protected $table = 'orderl';
	
	/**
	 * 提交订单
	 */
	public function store($number)
	{
		if(!$this->create()) return false;
		
		$total = $_SESSION['ORDERL']['total'];//订单商品总价
		$total_rows = $_SESSION['ORDERL']['total_rows'];//订单商品总条数
		$data = array(
			'number'=>$number,//订单号
			'consignee'=>Q('post.consignee'),//收货人
			'olphonenumber'=>Q('post.olphonenumber'),//收货人联系电话
			'address'=>Q('post.address'),//收货地址			
			'total'=>$total,//价格总计
			'total_rows'=>$total_rows,//订单总条数
			'time'=>time(),//订单时间
			'remark'=>Q('post.remark'),//订单备注
			'user_uid'=>$_SESSION['uid'],//用户id
		);
		
		$olid = $this->add($data);//添加成功之后返回的自增id
		//添加订单列表
		foreach ($_SESSION['ORDERL']['ord'] as $k => $v) {
			$olData = array(
				'quantity'=>$v['num'],//购买数量
				'subtotal'=>$v['total'],//价格小计
				'explain'=>'',//备注说明
				'glcolor'=>$v['options']['color'],//商品颜色
				'glsize'=>$v['options']['size'],//商品尺码
				'goods_gid'=>$v['shangpin']['gid'],//商品id
				'orderL_oid'=>$olid,//订单id			
			);
			$orderList = new \Home\Model\OrderList;
			$orderList->add($olData);
		}
		return true;				
	}
}
